package com.shsmi.dsn.controller;

import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.qiniu.util.Auth;
import com.shsmi.dsn.common.Constants;
import com.shsmi.dsn.common.Result;
import com.shsmi.dsn.domain.SystemUser;
import com.shsmi.dsn.service.AuthService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class HomeController {

    @Autowired
    private AuthService authService;

    @GetMapping(path = "/")
    public String index(){
        return "Server for DSN";
    }

//    @PostMapping(path = "/auth")
//    public Result auth(@RequestParam("loginName") String loginName,
//                       @RequestParam("password") String password){
////        JSONObject jsonObject = JSONUtil.parseObj(request);
////        String loginName = jsonObject.get("loginName").toString();
////        String password = jsonObject.get("password").toString();
//        SystemUser systemUser= authService.verify(loginName,password);
//        if(systemUser == null){
//            return Result.genFailResult();
//        }else{
//            return Result.genSuccessResult(systemUser);
//        }
//    }

    @GetMapping(path = "/upload_token")
    public Result uploadToken(){
        Auth auth = Auth.create(Constants.QINIU_AK, Constants.QINIU_SK);
        String token = auth.uploadToken(Constants.QINIU_BUCKET);
        return Result.genSuccessResult(token);
    }

}
